package com.qezhhnjy.mall.member.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.member.Member;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.member.service.MemberService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 会员 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "会员接口")
@Slf4j
@RequestMapping("/member")
public class MemberController {
    @Resource
    private MemberService memberService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取会员信息")
    public BaseResult<Member> get(Long id) {
        Member member = memberService.getById(id);
        return BaseResult.success(member);
    }

    @PostMapping("/save")
    @Operation(summary = "新增会员信息")
    public BaseResult<Member> save(@RequestBody Member member) {
        memberService.save(member);
        return BaseResult.success(member);
    }

    @PutMapping("/update")
    @Operation(summary = "更新会员信息")
    public BaseResult<Member> update(@RequestBody Member member) {
        memberService.updateById(member);
        return BaseResult.success(member);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取会员信息")
    public BaseResult<Page<Member>> page(@RequestBody Page<Member> page) {
        memberService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除会员信息")
    public BaseResult<Long> delete(Long id) {
        memberService.removeById(id);
        return BaseResult.success(id);
    }
}

